package com.clickpaas.timelineofUN.bean;

import com.bizcloud.ipaas.t7aef1c33e4a445f2833f9d631cb90c38.d20210202091529.codegen.*;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

@Component
public class ApiBean {
    /**
     * 项目API
     */
    private volatile ProjectApi _projectApi;
    @Bean
    public ProjectApi projectApi(){
        try {
            return getApi(ProjectApi.class,_projectApi);
        } catch (Exception e) {
            return new ProjectApi();
        }
    }

    /**
     * 项目方API
     */
    private static ProjectproviderApi _projectproviderApi;

    @Bean
    public ProjectproviderApi projectproviderApi() {
        try {
            return getApi(ProjectproviderApi.class,_projectproviderApi);
        } catch (Exception e) {
            return new ProjectproviderApi();
        }

    }

    /**
     * 注册用户API
     */
    private static SystemuserApi _systemuserApi;

    @Bean
    public SystemuserApi systemuserApi() {
        try {
            return getApi(SystemuserApi.class,_systemuserApi);
        } catch (Exception e) {
            return new SystemuserApi();
        }
    }

    /**
     * 动态更新API
     */
    private static UpdatedynamicsApi _updatedynamicsApi;

    @Bean
    public UpdatedynamicsApi updatedynamicsApi() {
        try {
            return getApi(UpdatedynamicsApi.class,_updatedynamicsApi);
        } catch (Exception e) {
            return new UpdatedynamicsApi();
        }
    }

    /**
     * 延迟加载
     * @param clazz
     * @param cla
     * @param <T>
     * @return
     * @throws Exception
     */
    private  <T> T getApi(Class<T> clazz,T cla) throws Exception {
        if (null == cla){
            synchronized (clazz){
                if (null == cla){
                    cla = clazz.newInstance();
                }
            }
        }
        return cla;
    }
}
